/**   
 * @Title: ViewerUtil.java 
 * @Package com.esun.util 
 * @Description: (视图工具类,存放通用视图类工具) 
 * @author 程相亭 <br/>
 * @date 2012-03-13 下午05:07:33  
 * copy right 深圳市易讯天空网络技术有限公司
 */
package com.esun.cheetah.view.personal.sportlotteryfootball;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.method.PasswordTransformationMethod;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.esun.cheetah.R;
import com.esun.cheetah.config.Language;
import com.esun.cheetah.view.HomeAct;
import com.esun.cheetah.view.personal.PersonalAct;
import com.esun.util.log.EDebug;

/**
 * com.esun.util.ViewerUtil
 * 
 * @Description: (视图工具类,存放通用视图类工具)
 * @author 程相亭 <br/>
 * @date 2012-03-13 下午05:07:33
 * 
 */
public class ViewerUtil {

	private static boolean IS_DIALOG_SHOW = false;
	public static boolean isShowRegist = false;

	/**
	 * 账户保护对话框
	 * 
	 * @param context
	 */
	public static void createDialog(Context context) {
		final Dialog inputPwdDialog = new Dialog(context, R.style.dialog);
		inputPwdDialog.getWindow().setContentView(
				R.layout.account_protect_dialog);
		Button btnYes = (Button) inputPwdDialog.getWindow().findViewById(
				R.id.btSure);
		((TextView) inputPwdDialog.getWindow().findViewById(
				R.id.tvPleaseInputPassword)).setText("请输入您的500WAN账户密码");
		final EditText edtPwd = (EditText) inputPwdDialog.getWindow()
				.findViewById(R.id.edtPawssWord);
		edtPwd.setTransformationMethod(PasswordTransformationMethod
				.getInstance());
		btnYes.setText("确定");
		btnYes.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (edtPwd.getText() != null
						&& edtPwd.getText().toString() != "") {
					inputPwdDialog.cancel();
				}
			}
		});
		Button btnNo = (Button) inputPwdDialog.getWindow().findViewById(
				R.id.btCancel);
		btnNo.setText("取消");
		btnNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				inputPwdDialog.cancel();
			}
		});
		inputPwdDialog.show();
	}

	public static void showTipDialog(final Context context, String strMsg,
			final boolean isActEnd) {
		EDebug.o("12312312312");
		final Dialog popTipDialog = new Dialog(context, R.style.dialog);
		popTipDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_showtipdialog);
		if (!IS_DIALOG_SHOW && !((Activity) context).isFinishing()) {
			EDebug.o("12312312312");
			popTipDialog.show();
			IS_DIALOG_SHOW = true;
			TextView tvMsg = (TextView) popTipDialog.getWindow().findViewById(
					R.id.viewerutildialogshowtipdialog_tv_msg);
			tvMsg.setText(strMsg);
			Button btnOk = (Button) popTipDialog.getWindow().findViewById(
					R.id.viewerutildialogshowtipdialog_btn_ok);
			btnOk.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					popTipDialog.dismiss();
					IS_DIALOG_SHOW = false;
				}
			});

			popTipDialog
					.setOnDismissListener(new DialogInterface.OnDismissListener() {

						@Override
						public void onDismiss(DialogInterface dialog) {
							// TODO Auto-generated method stub
							IS_DIALOG_SHOW = false;
							if (isActEnd) {
								((Activity) context).finish();
							}
						}
					});
		}
	}

	public static void showLogoutDialog(final Context context) {
		final Dialog logoutDialog = new Dialog(context, R.style.dialog);
		logoutDialog.getWindow().setContentView(
				R.layout.viewerutil_dialog_showlogout);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch (v.getId()) {
				case R.id.cancel:
					logoutDialog.dismiss();
					break;

				case R.id.sure:
					logoutDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass((Activity) context, HomeAct.class);

					HomeAct.flag = Language.FLAG_ONE;
					PersonalAct.flag = Language.FLAG_FIVE;
					context.startActivity(intent);

					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) logoutDialog.getWindow().findViewById(
				R.id.cancel);
		btnCancel.setOnClickListener(listener);
		Button btnRecharge = (Button) logoutDialog.getWindow().findViewById(
				R.id.sure);
		btnRecharge.setOnClickListener(listener);

		logoutDialog.show();
	}

	public static ProgressDialog showProgressDialog(Context context, String msg) {

		ProgressDialog progress = null;
		progress = new ProgressDialog(context);
		progress.setMessage(msg);

		progress.setOnKeyListener(new DialogInterface.OnKeyListener() {

			@Override
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {

				return true;

			}
		});

		return progress;
	}

}
